﻿Imports System
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Design
Imports System.Workflow.Runtime

Namespace System.Workflow.Activities
    Friend Class ActivityHelpers
        ' Methods
        Friend Shared Sub InitializeCorrelationTokenCollection(ByVal activity As Activity, ByVal correlator As CorrelationToken)
            If ((Not correlator Is Nothing) AndAlso Not String.IsNullOrEmpty(correlator.OwnerActivityName)) Then
                Dim ownerActivityName As String = correlator.OwnerActivityName
                Dim activityByName As Activity = activity.GetActivityByName(ownerActivityName)
                If (activityByName Is Nothing) Then
                    activityByName = Helpers.ParseActivityForBind(activity, ownerActivityName)
                End If
                If (activityByName Is Nothing) Then
                    Throw New ArgumentException("ownerActivity")
                End If
                Dim tokens As CorrelationTokenCollection = [TryCast](activityByName.GetValue(CorrelationTokenCollection.CorrelationTokenCollectionProperty),CorrelationTokenCollection)
                If (tokens Is Nothing) Then
                    tokens = New CorrelationTokenCollection
                    activityByName.SetValue(CorrelationTokenCollection.CorrelationTokenCollectionProperty, tokens)
                End If
                If Not tokens.Contains(correlator.Name) Then
                    tokens.Add(correlator)
                End If
            End If
        End Sub

    End Class
End Namespace

